package com.hp.bon.sgw.wh.channel.invoices.bizSlot;

import com.hp.bon.sgw.wh.channel.common.BizConsts;
import com.hp.bon.sgw.wh.channel.common.BizParam;
import com.hp.bon.sgw.wh.channel.common.BizResult;
import com.hp.bon.sgw.wh.channel.invoices.BizSlot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @PROJECT_NAME: SGW_WH2.1_TMALL
 * @DESCRIPTION:
 * @USER: YouQi
 * @DATE: 2021/5/8 14:31
 * 账务中心新接口
 * 缴费API—payment
 */
public class PaymentSlot implements BizSlot {

    private static final Logger LOG = LoggerFactory.getLogger(PaymentSlot.class);

    @Override
    public BizResult doBiz(BizParam bizParam) {
        LOG.info("start new  Payment......");
        BizResult bizResult = new BizResult();
        StringBuilder urlBuilder = new StringBuilder();

        String serialNumber = bizParam.getParamString(BizConsts.RQUEST_KEY_SERIALNUMBER);
        String lanId = bizParam.getParamString(BizConsts.KEY_INVOICE_LANID);

        //获取URL地址
        String url = bizParam.getParamString(BizConsts.KEY_ACCOUNT_API_URL);
        // 拼接get参数
        urlBuilder.append(url).append("?").append(BizConsts.RQUEST_KEY_SERIALNUMBER).append("=").append(serialNumber)
                .append("&").append(BizConsts.KEY_INVOICE_LANID).append("=").append(lanId);

        String respStr = HttpClientUtils.getHttpStr(urlBuilder.toString(),bizParam);
        if ("".equals(respStr)) {
            bizResult.setCode(BizConsts.STATUS_ACOUNT_API_FAIL);
            respStr = HttpClientUtils.getErrorJsonStr(BizConsts.STATUS_ACOUNT_API_FAIL, "", "", "");
        }else {

            bizResult.setCode(BizConsts.STATUS_ACOUNT_API_SUCCESS);
        }
        LOG.info("Responding to external messages====:{}",respStr);
        bizResult.setHttpBody(respStr);
        return bizResult;
    }
}
